package com.autodatabase.database;

import java.util.HashMap;
import java.util.Map;

import com.autodatabase.model.FactoryItemInfo;

public class DatabaseConnectionFactory {
	public DatabaseConnectionFactory() {
		super();
	}
	
	/**
	 * 获得链接，避免重复创建DatabaseConnection信息
	 * @param itemInfo
	 * @return
	 */
	public static DatabaseConnection getConnection(FactoryItemInfo itemInfo) {
		DatabaseConnection con = cons.get(itemInfo.getKey());
		
		if(con == null) {
			con = new DatabaseConnection(itemInfo);
			cons.put(itemInfo.getKey(), con);
		}

		return con;
	}
	
	private static Map<String, DatabaseConnection> cons = new HashMap<String, DatabaseConnection>();
}
